#!/bin/python3

import random
import time
import random

import carla

class Nature(object):
    def __init__(self, seed=None):
        self.seed = seed
        self.cloudiness = None # 0~100, 云的强度
        self.precipitation = None # 0~100， 雨的强度
        self.precipitation_deposits = None # 0~100，地面水渍的控制
        self.wind_intensity = None # 0~100， 风的强度
        self.sun_azimuth_angle = None # 0~360， 太阳的方位角
        self.sun_altitude_angle = None # -90~90， 太阳的高度角
        self.fog_density = None # 0~100， 雾的密度,只影响RGB相机

    def generate(self):
        if not self.seed:
            self.seed = time.time()
        random.seed(self.seed)
        self.cloudiness = random.betavariate(0.1, 1) * 100.0
        self.precipitation = random.betavariate(0.1, 1) * 100.0
        self.precipitation_deposits = random.betavariate(0.1, 1) * 100.0
        self.wind_intensity = random.betavariate(0.2, 1) * 100.0
        self.sun_azimuth_angle = random.uniform(89, 281) # 北半球
        self.sun_altitude_angle = random.uniform(-30, 90) # 夜晚的数据少一些，晚上开车的人少
        self.fog_density = random.betavariate(0.1, 1) * 100.0
        return carla.WeatherParameters(
            cloudiness=self.cloudiness,
            precipitation=self.precipitation,
            precipitation_deposits=self.precipitation_deposits,
            wind_intensity=self.wind_intensity,
            sun_azimuth_angle = self.sun_azimuth_angle,
            sun_altitude_angle = self.sun_altitude_angle,
            fog_density=self.fog_density
        )
        